<?php

/**
 * @name: HOTN Sponsor
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnsponsor/
 */

require_once("../../class2.php");

@include(e_PLUGIN."hotn_sponsor/languages/".e_LANGUAGE.".php");
@include(e_PLUGIN."hotn_sponsor/options.php");
include(e_PLUGIN."hotn_sponsor/hotn_sponsor_shortcodes_more.php");
if (file_exists(THEME."hotn_sponsor/hotn_sponsor_template.php"))
		include(THEME."hotn_sponsor/hotn_sponsor_template.php");
	else
		include(e_PLUGIN."hotn_sponsor/hotn_sponsor_template.php");
		
define("e_PAGETITLE",HOTN_SPONSOR_MORE_TITLE);

if (file_exists(THEME."hotn_sponsor/support_more.gif"))
		define("HOTN_SPONSOR_MORE_IMAGE",THEME."hotn_sponsor/support_more.gif");	
	elseif (file_exists(THEME."hotn_sponsor/support_more.png"))
		define("HOTN_SPONSOR_MORE_IMAGE",THEME."hotn_sponsor/support_more.png");	
	else
		define("HOTN_SPONSOR_MORE_IMAGE",e_PLUGIN."hotn_sponsor/images/support_more.png");

$HOTN_SPONSOR_MORE_TEXT = $tp->toHTML($_HOTN_SPONSOR_OPTIONS['hotn_sponsor_options_text'],true);
global $HOTN_SPONSOR_MORE_TEXT;

global $HOTN_SPONSOR_MONEY, $HOTN_SPONSOR_MORE_PERCENT, $HOTN_SPONSOR_MORE_USER, $HOTN_SPONSOR_MOUNTH;
$HOTN_SPONSOR_MONEY = 0;
$HOTN_SPONSOR_MORE_USER = "";
$sql = new db;

$sql->db_Select("hotn_sponsor_money","*");
while ($row = $sql->db_Fetch())
{
	if ($row['hotn_sponsor_money_minus'] == '1')
			$HOTN_SPONSOR_MONEY -= $row['hotn_sponsor_money_money'];
		else
			$HOTN_SPONSOR_MONEY += $row['hotn_sponsor_money_money'];
}

$HOTN_SPONSOR_MORE_PERCENT = round($HOTN_SPONSOR_MONEY/$_HOTN_SPONSOR_OPTIONS['hotn_sponsor_options_max']*500);

$mounth = array(
	HOTN_SPONSOR_MORE_MOUNTH_01,
	HOTN_SPONSOR_MORE_MOUNTH_02,
	HOTN_SPONSOR_MORE_MOUNTH_03,
	HOTN_SPONSOR_MORE_MOUNTH_04,
	HOTN_SPONSOR_MORE_MOUNTH_05,
	HOTN_SPONSOR_MORE_MOUNTH_06,
	HOTN_SPONSOR_MORE_MOUNTH_07,
	HOTN_SPONSOR_MORE_MOUNTH_08,
	HOTN_SPONSOR_MORE_MOUNTH_09,
	HOTN_SPONSOR_MORE_MOUNTH_10,
	HOTN_SPONSOR_MORE_MOUNTH_11,
	HOTN_SPONSOR_MORE_MOUNTH_12,
);

for($i=date("n")-1;$i<12;$i++)
{
	$HOTN_SPONSOR_MOUNTH[] = $mounth[$i];
}
for($i=0;$i<date("n")-1;$i++)
{
	$HOTN_SPONSOR_MOUNTH[] = $mounth[$i];
}

$HOTN_SPONSOR_MORE_BANK = $tp->toHTML($_HOTN_SPONSOR_OPTIONS['hotn_sponsor_options_bank'],TRUE);
global $HOTN_SPONSOR_MORE_BANK;
	
if ($_HOTN_SPONSOR_OPTIONS['hotn_sponsor_options_users_orderby']=="name")
{
	$ORDER_BY = "`user_loginname` ";
}
else
{
	$ORDER_BY = "`hotn_sponsor_money_money` ";
}
$ORDER_BY .= $_HOTN_SPONSOR_OPTIONS['hotn_sponsor_options_users_ordertype'];

$sql->db_Select("hotn_sponsor_money, ".MPREFIX."user","`user_id`,`user_login`,`user_name`,`user_loginname`,SUM(`hotn_sponsor_money_money`) as hotn_sponsor_money_money","user_id=hont_sponsor_money_user GROUP BY user_id ORDER BY ".$ORDER_BY);
while ($row = $sql->db_Fetch())
{
	if ($row['user_login']<>"")
		$name = $row['user_login'];
	else if ($row['user_name'] <> "")
		$name = $row['user_name'];
	else $name = $row['user_loginname'];
	
	$HOTN_SPONSOR_MORE_USER .= "<a href='".e_BASE."user.php?id.".$row['user_id']."'>".$name."</a><br />";
}

require_once(HEADERF);
$ns -> tablerender(HOTN_SPONSOR_MORE_TITLE, $tp->parseTemplate($HOTN_SPONSOR_MORE_TEMPLATE, false, $hotn_sponsor_more_shortcodes), "");
require_once(FOOTERF);
?>